package com.buddy.learn.javasource._lock;

/**
 * @author Buddy
 * @date 2021/5/15
 */
public class _volatile {

    private static volatile int stat = 1;

    public static void main(String[] args) {
        new Thread(() -> {
            while (stat == 1) {
                for (int i = 0; i < 10; i++) {
                    System.out.println("A " + i);
                }
                stat = 2;
                return;
            }
        }).start();
        new Thread(() -> {
            while (stat == 2) {
                for (int i = 0; i < 10; i++) {
                    System.out.println("B " + i);
                }
                stat = 3;
                return;
            }
        }).start();
        new Thread(() -> {
            while (stat == 3) {
                for (int i = 0; i < 10; i++) {
                    System.out.println("C " + i);
                }
                stat = 1;
                return;
            }
        }).start();
    }

}
